<!DOCTYPE html>
<html lang="en"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta content="webkit" name="renderer">
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">
    <link href="/layui-v2.6.4/layui/css/layui.css" media="all" rel="stylesheet">
    <script charset="UTF-8" src="/js/jquery-3.5.1.min.js"></script>
</head>
<body>

<table class="layui-hide" id="test" lay-filter="test"></table>
<script id="toolbarDemo" type="text/html">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
        <button class="layui-btn layui-btn-sm" lay-event="back">返回</button>
    </div>
</script>
<script id="barDemo" type="text/html">
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">返回</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script charset="utf-8" src="/layui-v2.6.4/layui/layui.js"></script>

<script th:inline="javascript" type="text/javascript">
    var typeID = /*[[${typeID}]]*/ 1;
    layui.use('table', function () {
        var table = layui.table;
        table.render({
            elem: '#test',
            url: '/getEntrustByType/' + typeID,
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.count, //解析数据长度
                    "data": res.data //解析数据列表
                }
            },
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            height: 'full-3',
            defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            title: '管理员数据表',
            cols: [
                [{
                    type: 'checkbox',
                    fixed: 'left'
                }, {
                    field: 'entrustId',
                    title: '委托号',
                    width: 100,
                    edit: 'text',
                    sort: true
                }, {
                    field: 'entData',
                    title: '委托类容',
                    width: 200,
                    edit: 'text'
                }, {
                    field: 'entConsignor',
                    title: '委托人编号',
                    width: 80,
                    edit: 'text'
                }, {
                    field: 'entAgent',
                    title: '代理人id',
                    width: 80,
                    edit: 'text',
                    sort: true
                }, {
                    field: 'entType',
                    title: '委托类型',
                    width: 110,
                    edit: 'text',
                    sort: true
                }, {
                    field: 'entPlan',
                    title: '进度安排',
                    width: 110,
                    edit: 'text',
                    sort: true
                }, {
                    field: 'entState',
                    title: '委托状态',
                    width: 150,
                    edit: 'text',
                    sort: true,
                    style: 'color:#269220'
                }]
            ]
        });
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：' + data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选' : '未全选');
                    break;
                case 'back':
                    location.assign("/toAddEntrustPage");
                    break;
                case 'LAYTABLE_TIPS':
                    layer.msg('这时管理员权限更改和查看页面');
                    break;
            }
        });

        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                location.assign("/toAddEntrustPage")
            } else {
                layer.confirm("是否删除该评论", function (index) {
                    $.ajax({
                        url: "/delReply"
                        , type: 'get'
                        , async: false
                        , data: {
                            id: data.id,
                        }, success: function (res) {
                            if (res === "1") {
                                obj.del();
                                layer.msg("成功")
                            } else {
                                layer.msg("故障了哦~请稍后重试")
                            }
                        }
                    });
                })
            }
        });
    });
</script>

</body>
</html>
